package util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.objenesis.instantiator.util.UnsafeUtils;
import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @ClassName UnsafeInstance
 * @date 2021/4/1 16:11
 * @Version 1.0
 * @Description //手动创建内存屏障
 * @USER root
 */
@Slf4j
public class UnsafeInstance {

    public static Unsafe reflectGetUnsafe() {
        try {
            Field field = Unsafe.class.getDeclaredField("theUnsafe");
            field.setAccessible(true);
            return (Unsafe) field.get(null);
        }catch (Exception e) {
            log.info(e.getMessage());
        }
        return null;
    }
}
